﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace XmlSpecParser
{
	public class DotNetFunctionData
	{
        public bool IsNative
        {
            get;
            set;
        }

		public string OriginalName
		{
			get;
			set;
		}

		public string NativeName
		{
			get;
			set;
		}

		public string DotNetName
		{
			get;
			set;
		}

		public string OriginalReturnType
		{
			get;
			set;
		}

		public string NativeReturnType
		{
			get;
			set;
		}

		public string DotNetReturnType
		{
			get;
			set;
		}

		public List<DotNetFunctionParamData> Params
		{
			get;
			set;
		}

		public int VersionMajor
		{
			get;
			set;
		}

		public int VersionMinor
		{
			get;
			set;
		}

		public bool CanPInvoke
		{
			get;
			set;
		}

		public bool IsUnsafe
		{
			get;
			set;
		}

		public bool ShouldUseGenerics
		{
			get;
			set;
		}

		public bool IsAtLeastOneParamNonVoidPointer
		{
			get { return this.Params.Where(x => x.IsPointer && x.NativeType != "IntPtr").Any(); }
		}
				
		public DotNetFunctionData()
		{
			this.Params = new List<DotNetFunctionParamData>();
		}

        public DotNetFunctionData Clone()
        {
            var copy = new DotNetFunctionData()
            {
                IsNative = this.IsNative,
                OriginalName = this.OriginalName,
                NativeName = this.NativeName,
                DotNetName = this.DotNetName,
                OriginalReturnType = this.OriginalReturnType,
                NativeReturnType = this.NativeReturnType,
                DotNetReturnType = this.DotNetReturnType,
                VersionMajor = this.VersionMajor,
                VersionMinor = this.VersionMinor,
                CanPInvoke = this.CanPInvoke,
                IsUnsafe = this.IsUnsafe,
                ShouldUseGenerics = this.ShouldUseGenerics
            };

            foreach (var param in this.Params)
                copy.Params.Add(param.Clone());

            return copy;
        }
    }
}
